email me at borlaj@portlandschools.org
notes previous (09/07/06) submit the dump links  
 

Hints:

//To find square root of 16
Math.sqrt(16);
//To find square of 4
Math.pow(4,2)
//To go through a word getting each letter
for (int i=0;i<word.length();i++)
	System.out.println(word.charAt(i));

 

 

HWJ7_MethodPractice - All must do 6, advanced do 10. Counts as 12 points.

 

Assignment: (in each method when I say take in; that means as a parameter - DO NOT USE THE SCANNER class)

 

 

  1. isEven that will take in an int as a parameter and will return true or false depending if its even.
    • to do this you will need to know about the % operator. You already know +-*/. % (Remainder or Mod) operator finds the remainder. So:
      • 16%3 would be 1 (if 16 is divided by 3 the remainder is 1)
      • 24%5 would be 4
      • 435%100 would be 35
      • 4%6 would be 4
  2. nextMultiple of 10 that will take in an int as a parameter and will return the next multiple of 10. (again use % remainder operator)
  3. toGrams that will take two doubles in pounds and ounces and return the number of grams
  4. daysInMonth that will take in an int (1-12) for the number of the month and return how many days it has in the month (this year)
  5. Create a method called convertToMiles that takes in kilometers as a double and returns the miles as a double
  6. Create a method called makeWheelOfForturne that will take in a String and replace all the vowels with '_'. It will then return that new word.
  7. Create a method called findDiagonal that will take in the width and height of television and it will return the diagonal. So 15,20, would return 25.
  8. stringBackwards that will take in a string as a parameter and return the string reversed.
  9. Create a method isPalindrome that takes in a String and determines if it is a palindrome (same forward as backward ie "dad") (call 8 above)
  10. Create a method called isLeapYear that will take in a year, and return true if it is a leap year, false otherwise. (The rules for leapYear are not as obvious as you thought. See here
  11. daysInMonth that will take in 2 ints (one for for the number of the month and one for the year) it will return an int and return how many days it has in that month.(for simplicity lets say every year divisible by 4 is a leap year)
  12. Create a method called ageInDays that will take in 4 arguments - your birth year, the number of your birth month (ie march is 3), number of day you were born. Find the number of days from then until today (November 3,2011)
    * you wont have to worry about leap years and lets just make a month 30 days
    * this method will return the number of days since you were born
    * for extra credit take in to account the leap years and different amount of days in a month. Use the methods you wrote in 5 and 6.

 

Extra Credit:

1. Look at this page. Create a method getHour() that will return the current hour in military time (ie 2pm would return 14) as an int.

2.Look at this page. Create a method getMin() that will return the current minute as an int.
3. Create a method ageInSeconds that will 4 arguments - your birth year, the number of your birth month (ie march is 3), number of day you were born. Find the number of seconds until now: Use 10:00 today if you want.